package com.jarvis.core.match;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import net.bytebuddy.matcher.ElementMatcher;

public class ProtectiveShieldMatcher<T> extends ElementMatcher.Junction.AbstractBase<T> {

  private static final Log logger = LogFactory.get(ProtectiveShieldMatcher.class);

  private final ElementMatcher<? super T> matcher;

  public ProtectiveShieldMatcher(ElementMatcher<? super T> matcher) {
    this.matcher = matcher;
  }

  public boolean matches(T target) {
    try {
      return this.matcher.matches(target);
    } catch (Throwable t) {
      if (logger.isDebugEnabled()) {
        logger.debug(t, "Byte-buddy occurs exception when match type.");
      }
      return false;
    }
  }
}